<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>错误！</strong>
	无效的付款计划信息！
</div>
<#else>
<form class="contract-payout-form" action="${request.contextPath}/contract/payout-money-by-plan" method="post">
	<input type="hidden" name="planId" value="${data.id}" />
	<input type="hidden" name="contract.id" value="${cid}" />
	<input type="hidden" name="payOut" value="true" />
	<input type="hidden" name="inAccount" value="true" />
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							收款单位
						</div>
					</div>
					<input type="text" class="form-control not-empty" name="source" value="${data.moneyTo}" placeholder="最多50个汉字" readonly="readonly"/>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							付款金额
						</div>
					</div>
					<input type="text" class="form-control number not-empty" name="total" value="${data.total}" placeholder="只能是数字"></textarea>
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							付款日期
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" data-format="yyyy-MM-dd" data-foot="false" data-time="${data.payoutTime}" name="time" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							发票
						</div>
					</div>
					<select class="form-control not-empty" name="invoice">
						<option value="false" selected>未收</option>
						<option value="true">已收</option>
					</select>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							发票说明
						</div>
					</div>
					<textarea rows="3" class="form-control" name="invoiceDes" placeholder="最多1000个中文"></textarea>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							备注
						</div>
					</div>
					<textarea rows="5" class="form-control" name="remark" placeholder="最多1000个中文">${data.reason}</textarea>
				</div>
			</div>
		</div>
	</div>
	<hr>
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">关闭</div>
		</div>
	</div>
</form>

<script src="${request.contextPath}/core/js/jquery.form.js"></script>
<script src="${request.contextPath}/js/suredy-datetimepicker.js"></script>
<script src="${request.contextPath}/app/js/form-checker.js"></script>
<script type="text/javascript">
	$(function() {
		// 初始化日期控件
		$.suredy.datetimepicker.init();

		$('form.contract-payout-form .btn-submit').on('click', function() {
			var form = $('form.contract-payout-form');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var $this = $(this);
			var okBtn = $('form.contract-payout-form .btn-submit');

			if (okBtn.hasClass('disabled'))
				return false;

			okBtn.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '付款失败!');
						okBtn.removeClass('disabled');
						return false;
					}

					refresh();

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('付款失败!\n' + errorThrown);
					okBtn.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
